import subprocess
import time


class XHS:
    note = 'am start -d xhsdiscover://item/{note_id} -a android.intent.action.VIEW'


def execute_shell(shell):
    """
    执行命令，返回执行结果
    :param shell:
    :return:
    """
    out_bytes = subprocess.check_output(shell, shell=True)
    out_text = out_bytes.decode("utf-8").replace("\n", "").strip()
    return out_text


def uiautomator2_init():
    """
    :return:
    """
    shells = [
        "su -c '/data/local/tmp/atx-agent server --stop'",
        "su -c '/data/local/tmp/atx-agent server --nouia -d'",
    ]
    for shell in shells:
        execute_shell(shell)
        time.sleep(1)
